package com.twu.biblioteca;

import com.twu.biblioteca.menu.Menu;
import com.twu.biblioteca.users.AuthenticateUser;
import com.twu.biblioteca.users.User;
import com.twu.biblioteca.users.UserSession;

import java.util.Scanner;

public class BibliotecaApp {

    public static ThreadLocal<UserSession> loggedInUser;

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        AuthenticateUser authenticateUser = new AuthenticateUser();
        authenticateUser.promptUserForCredentials();
        String[] loginCredentials = input.nextLine().trim().split(" ");
        authenticateUser.captureUserNameAndPassword(loginCredentials[0], loginCredentials[1]);

        loggedInUser = new ThreadLocal<UserSession>();
        try{
            loggedInUser.set(UserSession.getInstance(authenticateUser.validateUser()));
        }catch (NullPointerException e){
            System.out.println("You are not logged in so you might not be able to do perform all operations");
        }

        Menu menu = new Menu();
        Menu.OPTIONS option;
        menu.printWelcomeMessage();
        option = menu.processUserInput(input.nextInt());
        option.execute();

    }
}
